﻿var lvData;

function Page_Load(sender, e)
{ 
    state = "Alabama";
    state = System.Gadget.Settings.read('state');
    
    lvData = $find('lvData');
    
    PerDiemService.GetRatesByState(state, 
                                    OnGetRatesByStateComplete,
                                    OnError);    
	
	// Set focus to close button
	window.setTimeout('setFocus()', 500);
}

function setFocus()
{
	btnCloseFlyout.focus();
}

function lvData_RenderComplete()
{
    //write some logic to adjust the height of the flyout
    //based on the # of rows
    
    //NEED TO WORK WITH JAMES ON THIS...
}

function OnGetRatesByStateComplete(response)
{
	divMain.style.display = "none";    
    lvData.set_data(response);
    //divMain.style.display = "block";    
	
	// Get the dom elements to animate
	var loadingDiv = new Sys.UI.Control($get("divGettingData"));
	var mainDiv = new Sys.UI.Control($get("divMain"));
	
	// fade the loading div
	var a1 = new Sys.Preview.UI.Effects.FadeAnimation();
	a1.set_target(loadingDiv);
	a1.set_effect(Sys.Preview.UI.Effects.FadeEffect.FadeOut);
	
	// Slide the main div down
	var a2 = new Sys.Preview.UI.Effects.NumberAnimation();
    a2.set_target(mainDiv);
    a2.set_property("style");
    a2.set_propertyKey("height");
    a2.set_integralValues(true);
    a2.set_startValue(1);
    a2.set_endValue(700);
        
    var animationSet = new Sys.Preview.UI.Effects.CompositeAnimation();
	animationSet.get_animations().add(a1);
	//animationSet.get_animations().add(a2);
	animationSet.set_duration(0.3);
	animationSet.set_fps(40);
	animationSet.play();
	
	// Temp workaround until animation figured out...
	divMain.style.display = "block"; 
}

function OnError(error)
{
    divGettingData.style.display = "none";
    divMain.style.display = "none";
    divSericeNotAvailable.style.display = "block";
}

function btnCloseFlyout_Click(e)
{
    System.Gadget.Flyout.show = false;
}

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
